package jkmgWin

import (
	"github.com/lxn/walk"
	. "github.com/lxn/walk/declarative"

	"jk/jklog"
)

type MongoWin struct {
	*walk.MainWindow
	lb     *walk.ListBox
	lsName *ListName
}

type MyNames struct {
	name   string
	author string
}

type ListName struct {
	walk.ListModelBase
	item []MyNames
}

func newListName() *ListName {
	return &ListName{}
}

func (l *ListName) ItemCount() int {
	return len(l.item)
}

func (l *ListName) Value(index int) interface{} {
	return l.item[index].name
}

func MongoWindow(parent walk.Window) {
	mw := &MongoWin{lsName: newListName()}

	main := MainWindow{
		AssignTo: &mw.MainWindow,
		Title:    "数据库",
		MinSize:  Size{400, 280},
		Layout:   VBox{},
		Children: []Widget{
			VSplitter{
				Children: []Widget{
					ListBox{
						AssignTo: &mw.lb,
						Model:    mw.lsName,
					},
				},
			},
		},
	}

	err := main.Create()
	if err != nil {
		jklog.L().Fatal(err)
	}

	mw.Run()
}
